package com.cb.web.wasf.sample.model;

import com.cb.web.wasf.Principal;
import java.io.Serializable;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

/**
 * @author CBO
 */
public class PrincipalImpl extends Principal implements Serializable {

    private UserBO user;
    private Set<String> roles;

    public PrincipalImpl(UserBO user, Collection<RoleBO> roles) {
        this.user = user;
        this.roles = new HashSet<String>();
        for (RoleBO role : roles) {
            this.roles.add(role.getName());
        }
    }

    public UserBO getUser() {
        return this.user;
    }

    @Override
    public boolean hasRole(String role) {
        return roles.contains(role);
    }
}
